//
//  main.cpp
//  运算符重载
//
//  Created by linjinzhu on 2017/7/11.
//  Copyright © 2017年 linjinzhu. All rights reserved.
//

#include <iostream>

using namespace std;


/// 函数重载：重载的函数参数个数、参数类型、参数顺序不同
class PrintData {

public:
    void print(double a) {
        cout << a << endl;
    }

    void print(int a) {
        cout << a << endl;
    }

    void print(char a) {
        cout << a << endl;
    }

    PrintData() {
        cout << "call constructor" << endl;
    }

    ~PrintData() {
        cout << "free memory" << endl;
    }
};

/// 运算符重载

class Box {
private:
    int x,y,z;
public:
    Box(int _x,int _y,int _z) {
        x = _x;
        y = _y;
        z = _z;
    }

    Box(){x=y=z=0;}

    int volume() {
        return x*y*z;
    }

    Box operator+(const Box& b) {
        Box box;

        box.x = this->x + b.x;
        box.y = this->y + b.y;
        box.z = this->z + b.z;

        return box;
    }
};

int main(int argc, const char * argv[]) {

    PrintData pd;
    pd.print(123);
    pd.print(double(123.0));
    pd.print('a');

    Box b1(1,1,1);
    Box b2(2,2,2);

    Box b3 = b1 + b2;

    pd.print(b1.volume());
    pd.print(b2.volume());
    pd.print(b3.volume());




    return 0;
}
